<!--
 * @Description:5秒跳回首页
 * @Author: Sun
 * @Date: 2019-07-01 20:05:50
 * @LastEditors: Sun
 * @LastEditTime: 2019-07-13 18:19:32
 -->
<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>5秒跳回首页</title>
	<style>

	</style>
	<script>
		window.onload = function () {
			var timer = null;
			var btn = document.getElementById("demo")
			var mk = document.getElementById("mk")
			var count=8;
			var speed=1000
			setTimeout(goIndex,speed)
			function goIndex(){ 
				count--;
				if(count<=0){
					window.location.href="https://www.baidu.com/"
				}else{
					setTimeout(goIndex,speed) //定时器再开一个函数 递归函数
					mk.innerHTML=`<a href='https://www.baidu.com/'>还有${count}跳回首页</a>`
				}
			}

		}
	</script>
</head>

<body>
	<div id="demo"></div>
	<h1 id="mk"></h1>
</body>

</html>